package Year21_Month11.day1111;

public class Soultion {
    public static int[] exchange(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        while(left < right){
            if(nums[left] % 2 == 0 && nums[right] % 2 != 0){
                int tmp = nums[left];
                nums[left] = nums[right];
                nums[right] = tmp;
            }else if(nums[left] % 2 != 0){
                left++;
            }else if(nums[right] % 2 == 0){
                right--;
            }
        }
        return nums;
    }

    public static void print(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,4};
        int[] arr1 = exchange(arr);
        print(arr1);
    }
}
